﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Prime_number
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.Write("请输入一个正整数:");
            int num = int.Parse(Console.ReadLine());

            int[] factors = GetPrimeFactors(num);

            Console.WriteLine($"{num}的所有不重复素数因子为:");
            foreach (int factor in factors)
            {
                Console.Write(factor + " ");
            }
            Console.WriteLine();
        }

        static int[] GetPrimeFactors(int n)
        {
            int[] factors = new int[100];
            int count = 0;

            for (int i = 2; i <= n; i++)
            {
                while (n % i == 0)
                {
                    n /= i;
                    if (!factors.Contains(i))
                    {
                        factors[count++] = i;
                    }
                }
            }

            Array.Resize(ref factors, count);
            return factors;


        }
    }
}
